// ---------------------------------------------------------------------
//
// -- 尺寸信息
// -- author £
//
// ---------------------------------------------------------------------

const ORIGIN_W = 750,
    ORIGIN_H = 1624,
    DESIGN_H = 1334,
    RANK_ITEM_H = 92,
    ORIGIN_RANK_ITEM_COUNT = 8,
    FINISH_COLOR = '#252550';

let _visibleW = 0,
    _visibleH = 0,
    _realW = 0,
    _realH = 0,
    _scaleW = 0,
    _rankDItemCount = 0;

// let wx;

let UIManager = {
    startup: function (wx) {
        // let size = cc.view.getFrameSize();
        let isWX = wx,
            size = isWX ?
                cc.view.getVisibleSize() :
                cc.view.getFrameSize();

        _visibleW = size.width;
        _visibleH = size.height;

        // if (cc.sys.isMobile && !isWX) {
        //     _visibleW = _visibleH;
        //     _visibleH = size.width;
        // }

        _realW = ORIGIN_W;
        _scaleW = ORIGIN_W / _visibleW;
        _realH = ORIGIN_W / _visibleW * _visibleH;

        // if (isWX && cc.sys.os === cc.sys.OS_IOS) {
        //     wx.setStatusBarStyle({
        //         style: 'white'
        //     });
        // }

        // if (isWX) {
        //     let openDataContext = wx.getOpenDataContext();
        //     let sharedCanvas = openDataContext.canvas;

        //     if (sharedCanvas) {
        //         sharedCanvas.width = _realW;
        //         sharedCanvas.height = _realH;
        //     }
        // }

        let dh = this.getDeltaH(),
            listDH = 0, listDC = 0,
            isPositive = dh >= 0,
            absDH = Math.abs(dh);

        if (absDH >= RANK_ITEM_H) {
            listDC = Math.floor(absDH / RANK_ITEM_H) * (isPositive ? 1 : -1);
            listDH = listDC * RANK_ITEM_H;
            _rankDItemCount = listDC;
        }

        console.log('UI DATA========================');
        console.log(_realW, _realH);
        console.log(_visibleW, _visibleH);
        console.log(_scaleW);
        console.log('UI DATA========================');
    },

    getRootY: function () {
        return _realH * 0.5;
    },

    getRealW: function () {
        return _realW;
    },

    getRealH: function () {
        return _realH;
    },

    getDesignScale: function () {
        if (_realH >= DESIGN_H) return 1;

        return _realH / DESIGN_H;
    },

    getDeltaH: function () {
        return _realH - DESIGN_H;
    },

    getRealHC: function () {
        return (ORIGIN_H - _realH) * 0.5;
    },

    getDesignHC: function () {
        return (DESIGN_H - _realH) * 0.5;
    },

    getScaleW: function () {
        return _scaleW;
    },

    getVisibleW: function () {
        return _visibleW;
    },

    getRankItemCount: function (sp) {
        return _rankDItemCount + ORIGIN_RANK_ITEM_COUNT + (sp ? -1 : 0);
    },

    getRankBgDH: function () {
        return RANK_ITEM_H * _rankDItemCount;
    },

};

module.exports = UIManager;